package com.wuchengdong.web.controller;

import com.wuchengdong.web.extend.utils.R;
import com.wuchengdong.web.pojo.Employee;
import com.wuchengdong.web.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/employee")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;
    @GetMapping
    public R<List<Employee>> getAll(){
        return R.success(employeeService.list());
    }

    @GetMapping("/getById")
    public R<Employee> getById(Employee employee) {
        return R.success(employeeService.getById(employee.getId()));
    }

    @PostMapping
    public R<String> saveOrUpdate(@RequestBody Employee employee) {
        return employeeService.saveOrUpdate(employee) ? R.success("success") : R.error("error");
    }

    @DeleteMapping
    public R<String> deleteById(@RequestBody Employee employee) {
        return employeeService.removeById(employee) ? R.success("success") : R.error("error");
    }
}
